package com.qf.eduadmin.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.eduadmin.mapper.QfTeachDao;
import com.qf.eduadmin.pojo.vo.QfTeach;
import com.qf.eduadmin.pojo.resp.ResponseData;
import com.qf.eduadmin.service.QfTeachService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (QfTeach)表服务实现类
 *
 * @author makejava
 * @since 2021-12-25 17:17:30
 */
@Service
public class QfTeachServiceImpl implements QfTeachService {
    @Resource
    private QfTeachDao qfTeachDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public ResponseData queryById(Integer id) {
        QfTeach qfTeach = qfTeachDao.queryById(id);
        if(qfTeach!=null){
            return new ResponseData(0,"查询成功",qfTeach,null);
        }
        return new ResponseData(1,"查询失败",null,null);
    }

    /**
     * 查询多条数据
     *
     * @return 对象列表
     */
    @Override
    public ResponseData queryAllByLimit(Integer page,Integer limit) {
        PageHelper.startPage(page,limit);
        List<QfTeach> qfTeaches = qfTeachDao.queryAllByLimit();
        PageInfo<QfTeach> alls = PageInfo.of(qfTeaches);
        if (qfTeaches!=null){
            return new ResponseData(0,"查询成功",alls.getList(),alls.getTotal());
        }
        return null;
    }

    /**
     * 新增数据
     *
     * @param qfTeach 实例对象
     * @return 实例对象
     */
    @Override
    public ResponseData insert(QfTeach qfTeach) {
        Integer i = qfTeachDao.insert(qfTeach);
        if(i!=null){
            return new ResponseData(0,"添加老师成功",null,null);
        }
        return null;
    }

    /**
     * 修改数据
     *
     * @param qfTeach 实例对象
     * @return 实例对象
     */
    @Override
    public ResponseData update(QfTeach qfTeach) {
        Integer integer = qfTeachDao.update(qfTeach);
        if (integer!=null){
            return new ResponseData(0,"修改成功",null,null);
        }
        return new ResponseData(1,"修改失败",null,null);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public ResponseData deleteById(Integer id) {
        Integer integer = qfTeachDao.deleteById(id);
        if(integer!=null){
            return new ResponseData(0,"删除成功",null,null);
        }
        return new ResponseData(1,"删除失败",null,null);
    }

    /**
     * 查询所有不拦截
     * @return
     */
    @Override
    public ResponseData findAllTeacher() {
        List<QfTeach> qfTeaches = qfTeachDao.queryAllByLimit();
        if(qfTeaches.size()>0){
            return new ResponseData(0,"查询成功",qfTeaches,null);
        }
        return new ResponseData(1,"查询失败",null,null);
    }
}